﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.Presenter.ReasignarDocumento;
using Microsoft.Office.Server.UserProfiles;
using System.Collections.Generic;
using MS.InformationManagement.Support;
using System.Web;
using MS.InformationManagement.DAL.DTOs;

namespace MS.InformationManagement.WP.DocumentCenter.ReasignarDocumento
{
    public partial class ReasignarDocumentoUserControl : BaseControl, IReasignarDocumentoView
    {

        #region fields

        private ReasignarDocumentoPresenter _presenter;

        #endregion

        #region Properties

        public string CurrentListId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["lstID"]))
                    return null;
                else
                    return Page.Request.QueryString["lstID"];
            }
        }
        public string CurrentItemsId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["itemsID"]))
                    return null;
                else
                    return Page.Request.QueryString["itemsID"];
            }
        }
        public List<UserDTO> listUsuariosDepartamento { get; set; }
        public string LoginName { get; set; }
        public string RadicadoMove { get; set; }

        #endregion

        #region Form Events

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                _presenter = new ReasignarDocumentoPresenter(this);
                if (!IsPostBack)
                    _presenter.HandleLoad();
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Page.RegisterAjaxLoaderPlugin();
            btnGuardar.AddLoader();
        }

        protected void Action_Save(object sender, EventArgs e)
        {
            try
            {
                LoginName = ddlUsuariosDepartamentos.SelectedItem.Value;
                _presenter.HandleSave();
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }

        protected void Action_Cancel(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        public new event Presenter.Support.Events.ErrorHandler OnError;

        public event Presenter.Support.Events.SuccessHandler OnSuccess;

        #endregion

        #region Implemented Methods

        public void Show()
        {
            ddlUsuariosDepartamentos.DataSource = listUsuariosDepartamento;
            ddlUsuariosDepartamentos.DataBind();
            ddlUsuariosDepartamentos.SelectedIndex = 0;
            if (listUsuariosDepartamento.Count <= 0)
            {
                btnGuardar.Enabled = false;
            }
        }

        public void Success()
        {
            this._ShowAlertAndClose(RadicadoMove);
        }

        #endregion
    }
}
